//
//  TKL_mineVC.m
//  TKL_EnPro
//
//  Created by 雅恩三河科技 on 2018/12/11.
//  Copyright © 2018年 MrZhang. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "TKL_mineVC.h"

#import "Head.h"
#import "TKL_mineCell.h"
#import "TKL_TopCell.h"
#import "TKL_MySetInfoVC.h"
@interface TKL_mineVC ()
@property(nonatomic,strong)NSMutableDictionary* dataSource;

@end

@implementation TKL_mineVC
#pragma mark - getter and setter
-(NSMutableDictionary *)dataSource
{
    if (!_dataSource) {
        _dataSource=[NSMutableDictionary new];
    }
    return _dataSource;
}
#pragma mark - event
#pragma mark - method
-(void)initilization
{
    self.isGroup=YES;
    [self setNavgationTheme:2];
    self.navigationItem.title = @"";
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [self.view addSubview:self.baseTable];

    self.baseTable.contentInset = UIEdgeInsetsMake(-2, 0, [self bottomShelterHeight], 0);
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    [self.baseTable setSeparatorColor: Main_Color_BG];
    [self.baseTable setBackgroundColor:Main_Color_BG];
    [self.baseTable setTintColor:Main_Color_BG];
    @WeakSelf;
    
    UIButton* MesBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage* btnImage=[UIImage imageNamed:@"setting"];
    [MesBtn setBackgroundImage:btnImage forState:UIControlStateNormal];
    MesBtn.width=btnImage.size.width;
    MesBtn.height=btnImage.size.width;
    MesBtn.x=SCREEN_WIDTH-MesBtn.width-20;
    MesBtn.y=(44-MesBtn.height)/2;
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:MesBtn];;
    [MesBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        Class class=NSClassFromString(@"TKL_SettingVC");
        if (class) {
            UIViewController* vc=[[class alloc] init];
            [selfp.navigationController pushViewController:vc animated:YES];
        }
    }];
    [self viewModelBand];
   // [self reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;
}
-(void)reloadData
{
    if ([TKL_LoginViewModel shareInterface].isLogin)
    {
        [self requestCityData];
    }else
    {
        [self setDataSource:nil];
    }
    [self.baseTable reloadData];
}
#pragma mark - life
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
     [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0) {
        return 1;
    }

     return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section==0)
    {
        static NSString *CellID = @"CellID0";
        TKL_TopCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[TKL_TopCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            
        }
        cell.height=WFCGFloatY(200);
        [cell setData:self.dataSource];
        return cell;
    }
    static NSString *CellID = @"CellID";
    TKL_mineCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[TKL_mineCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    NSArray* arr=@[
                       @{@"image":@"info_0",@"name":@"我的发布"},
                       @{@"image":@"info_1",@"name":@"通知消息"},
                       @{@"image":@"info_2",@"name":@"意见反馈"},
                       @{@"image":@"info_3",@"name":@"客服热线"}
                   ];
    cell.height=WFCGFloatY(50);
    [cell setItemDic:[arr objectAtIndex:indexPath.row]];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return WFCGFloatY(50);
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    CGFloat height = cell.height;
    return height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (![TKL_LoginViewModel shareInterface].isLogin) {
        [[GCPresenter shareInterface] loadLogin];
        return;
    }
    if (indexPath.section==0)
    {
        TKL_MySetInfoVC *vc = [[TKL_MySetInfoVC alloc]init];
        vc.passInfo=self.dataSource;
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.section==1)
    {
        if (indexPath.row==3) {
            [[GCPresenter shareInterface] phoneCall:@"400-000-0000"];
        }else
        {
            NSArray* arr=@[@"TKL_myPubBlogListVC",@"TKL_MessageVC",@"TKL_HunFeedbackVC"];
            Class class = NSClassFromString(arr[indexPath.row]);
            UIViewController *vc = [[class alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=Main_Color_BG;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return .00001f;
    }
    return 5;
}
////http://101.201.171.131:8080/rest/api/user/detail/ 用户详情  userUuid=63e5eeec-588a-4c66-9356-ab7b4313a020
-(void)requestCityData
{
    @WeakSelf;

    NSMutableDictionary* para=[NSMutableDictionary new];
    [para setObject:[TKL_LoginViewModel shareInterface].infoModel.uuid forKey:@"userUuid"];
    
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/user/detail" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        
         [selfp.dataSource removeAllObjects];
        selfp.dataSource=[[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:@"data"]];
        [selfp.baseTable reloadData];
        
    }];
    // 1544683517694
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
